package com.xinchao.ck_mips.utils;

import android.content.Context;
import android.content.Intent;

import com.xinchao.machine.digital_advertise.SimpleMachine;
import com.xinchao.machine.digital_advertise.tools.SharedPreferencesHelper;
import com.xinchao.machine.digital_advertise.tools.SwitchTools;

/**
 * 特殊机型适配
 */
public class HisiMachine extends SimpleMachine {
    public HisiMachine(Context context) {
        super(context);
    }

    @Override
    public int setSwitchTime(int on_h, int on_m, int off_h, int off_m) {
        // return -3 不支持 -2 无效的开关机时间 -1 设置失败[开机时间晚于关机时间] 0 清除开关机时间 1 设置成功
        if (SwitchTools.getInstance(getContext()).isWrongOnOffTime(on_h, on_m, off_h, off_m)) {
            return -2;//无效的开关机时间
        }
        if (SwitchTools.getInstance(getContext()).isOnOffTimeSame(on_h, on_m, off_h, off_m)) {
            setSwitchStatus(false);
            return 0;//清除开关机时间
        }

        if (SwitchTools.getInstance(getContext()).isOnTimeAfterOffTime(on_h, on_m, off_h, off_m)) {
            return -1;//开机时间晚于关机时间
        }

        executeSuCommand("sync");
        setSwitchStatus(true);

        SharedPreferencesHelper.getInstance(getContext()).put("on_h", on_h);
        SharedPreferencesHelper.getInstance(getContext()).put("on_m", on_m);
        SharedPreferencesHelper.getInstance(getContext()).put("off_h", off_h);
        SharedPreferencesHelper.getInstance(getContext()).put("off_m", off_m);

        HisiDeviceUtil.setPowerOnOff(getContext(), on_h, on_m, off_h, off_m, true);
        checkOnOffTime(true, true, null);
        return 1;
    }

    @Override
    public void power_off() {
        Intent intent = new Intent(HisiDeviceUtil.ACTION_SHUTDOWN);
        HisiDeviceUtil.sendBroadcast(getContext(), intent);
    }



    @Override
    public void reboot() {
        Intent intent = new Intent(HisiDeviceUtil.ACTION_REBOOT);
        HisiDeviceUtil.sendBroadcast(getContext(), intent);
    }

}
